Imports Microsoft.Xna.Framework
Imports Microsoft.Xna.Framework.Audio
Imports Microsoft.Xna.Framework.Graphics
Imports Microsoft.Xna.Framework.Input
Imports Microsoft.Xna.Framework.Input.Touch
Imports Microsoft.Xna.Framework.Content
Imports System.Collections.Generic
Imports System.Configuration

Public Class Sequence
	Implements ICloneable
	Private Const FRAME_WIDTH As Integer = 114
	Private Const FRAME_HEIGHT As Integer = 114
	'public const float FRAME_TIME = 0.1f;

	Public config_type As String

	Public frames As New List(Of Frame)()
	Public name As String
	Public raised As Boolean = False
	Public tileType As Enumeration.TileType
	Public collision As Enumeration.TileCollision

	''' <summary>
	''' Get the Total xOffset and yOffset
	''' 
	''' </summary>
	''' <retur>
	''' Vector2
	''' </retur>
	Public ReadOnly Property CountOffSet() As Vector2
		Get
			If Me Is Nothing Then
				Return Vector2.Zero
			End If
			Dim x As Integer = 0, y As Integer = 0
			For Each f As Frame In frames
				x += f.xOffSet
				y += f.yOffSet
			Next
			Return New Vector2(CInt(x), CInt(y))
		End Get
	End Property



	Public Sub Initialize(Content As ContentManager)
		For Each f As Frame In frames
			Try
				'loading texture
				If f.value IsNot Nothing Then
					Dim t As Texture2D = Nothing
					#If WINDOWS Then
                    t = DirectCast(Maze.dContentRes(System.Configuration.ConfigurationManager.AppSettings(config_type).ToString().ToUpper() & f.value.ToUpper()), Texture2D)

					#End If
					#If ANDROID Then

					#End If
					If t Is Nothing Then
						f.SetTexture(Nothing)
					Else
						f.SetTexture(t)
					End If
				End If
				'loading sound
				If f.sound IsNot Nothing Then
					Dim s As SoundEffect = DirectCast(Maze.dContentRes(PrinceOfPersiaGame.CONFIG_SOUNDS & f.sound.ToUpper()), SoundEffect)
					f.SetSound(s)
				End If
			Catch ex As Exception
				System.Console.WriteLine("ERROR:Content.Load<dContentRes>" & ex.ToString() & config_type.ToUpper() & f.value)
			End Try
		Next
	End Sub

	' Deep clone
	Public Function DeepClone() As Sequence
		Dim newSequence As New Sequence()
		newSequence.name = Me.name
		newSequence.raised = Me.raised
		newSequence.collision = Me.collision
		newSequence.tileType = Me.tileType

		'newSequence.frameTime = this.frameTime;
		For Each f As Frame In Me.frames
			newSequence.frames.Add(f.DeepCopy())
		Next
		Return newSequence

	End Function


	Private Function ICloneable_Clone() As Object Implements ICloneable.Clone
		Return Me.Clone()
	End Function
	Public Function Clone() As Sequence
		Return DirectCast(Me.MemberwiseClone(), Sequence)
	End Function



End Class
